Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

173
Views
How to keep the content of a span together when resizing window (how to "word-break" at span boundaries)?

In my case, &nbsp doesn't work. I have a span containing a react icon and a number next to it on the right side (think a star icon and a user rating). When I resize my viewport to a certain breakpoint, the number on the right shifts down to a new line, but the icon stays in place. I'd like to make it so that if there isn't enough space for the icon and number to be displayed together on that line, then they both move down to a new line, so that the icon and number are never broken apart.

The code looks something like:

  <p className={styles["key-info"]}>
    <span>
      {release ? release.substring(0, 4) : "Unknown Release Date"}
    </span>
    <span> &#183; {rating}</span>
    <span> &#183; {formatMinutes(runtime)}</span>
    <span>
      {" "}
      &#183; <FaStar className={styles["star-icon"]} />
      {score}
    </span>
  </p>

How do I ensure that my spans are kept together when resizing the window and in particular in the case of the last span, how do I prevent the number on the right (score) from hopping to a new line without the icon, and then the icon hopping down when the window is resized even further? I read somewhere that   should work, but it doesn't.

Hope what I'm asking is pretty clear. If not, I'd be happy to clarify. I should also mention that the thing which is causing the content to break to a new line is the container shrinking. Maybe that's relevant.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Try putting them under one div

<div class="together">
<FaStar className={styles["star-icon"]} />
      {score}
</div>

and then set the

white-space:nowrap;
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!